package com.zosoft.responseResult;


import com.jfinal.kit.Prop;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.Record;

public class Result {

	private Object  data;
	private String message;
	private int resultCode;
	private Object ext;
	
	
	protected final static Prop p =  PropKit.use("response.properties");
	
	public   Result(){
		this.resultCode =getSuccessresultCode();
		this.message =getMessageByresultCode(this.resultCode);
		this.data = null;
		this.ext = null;

	} 
	
	public Result(int resultCode,String  message,Object data,Object ext){
		this.resultCode =resultCode;
		this.message =message;
		this.data = data;
		this.ext = ext;
	}
	
	
	public  Result(int resultCode){
		this.resultCode = resultCode;
		this.message =getMessageByresultCode(this.resultCode);
		this.data = null;
		this.ext = null;
	}
	
	public   Result(int resultCode ,Object data){
		this.resultCode = resultCode;
		this.message =getMessageByresultCode(this.resultCode)!=""?getMessageByresultCode(this.resultCode):data+"";
		this.data = getMessageByresultCode(this.resultCode)!=""?data:null;
		this.ext = null;
	}
	
	public   Result(Object data){
		this.resultCode = getSuccessresultCode();
		this.message =getMessageByresultCode(this.resultCode);
		this.data = data;
		this.ext = null;
	}
	
	public  Result(int resultCode ,Object data,Object ext){
		this.resultCode = resultCode;
		this.data = data;
		this.ext = ext;
	}
	
	public  Result(Object data,Object ext){
		this.resultCode = getSuccessresultCode();
		this.message =getMessageByresultCode(this.resultCode);
		this.data = data;
		this.ext = ext;
	}
	
	
	protected int getSuccessresultCode(){
		int resultCode = 0;
		try {
			resultCode = Integer.valueOf(p.get("success"));
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return resultCode;
	}
	
	
	protected String getMessageByresultCode(int resultCode){		
		return p.get(""+resultCode, "");
	}
	
	

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public int getresultCode() {
		return resultCode;
	}

	public void setresultCode(int resultCode) {
		this.resultCode = resultCode;
	}

	public Object getExt() {
		return ext;
	}

	public void setExt(Object ext) {
		this.ext = ext;
	}

	
}
